# -*- encoding: utf-8 -*-
from django.db import models
from multilingual.translation import TranslationModel
from django.utils.translation import ugettext_lazy as _

from modulo.page.models import Section

class Map(models.Model):
    section = models.ForeignKey(Section, related_name="maps",
                                limit_choices_to = {'app': 'map'},
                                help_text=_(u"Selection de la rubrique contenant ce lieu."))

    map_lat = models.CharField(_(u'Latitude'), max_length=25, help_text=u"<a href='#' onclick=\"window.open('/admin/map/select_map/', 'select_form', 'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=500,height=400');return false;\">Séléctionner sur la carte</a>")
    map_lon = models.CharField(_(u'Longitude'), max_length=25)

    order = models.IntegerField(editable=False, default=0)

    class Translation(TranslationModel):
        name = models.CharField(_(u'Nom'), max_length=30)
        comment = models.CharField(_(u'Description'), max_length=150)

    class Meta:
        ordering = ['order']

    def get_absolute_url(self):
        return u"%s#scenes" % self.section.get_absolute_url()

    def save(self):
        if self.order == 0:
            self.order = Map.objects.count()+1
        super(Map, self).save()
        
    def __unicode__(self):
        return u"%s" % (self.name)
